#include "stdafx.h"
#include "UIImageSource.h"


namespace DirectUI
{
	CUIImageSource::CUIImageSource(void)
	{
		m_rcValidImageArea.SetRectEmpty();
		m_rcNineGrid.SetRectEmpty();
	}

	CUIImageSource::~CUIImageSource(void)
	{
	}

	LPCTSTR CUIImageSource::GetResName()
	{
		return m_szResName;
	}

	void CUIImageSource::SetResName( LPCTSTR lpszResName )
	{
		m_szResName = lpszResName;
	}

	LPCTSTR CUIImageSource::GetImageFilePath()
	{
		return m_szImageFilePath;
	}

	void CUIImageSource::SetImageFilePath( LPCTSTR lpszFileSource )
	{
		m_szImageFilePath = lpszFileSource;
	}

	RECT CUIImageSource::GetValidImageArea()
	{
		return m_rcValidImageArea;
	}

	void CUIImageSource::SetValidImageArea( RECT rc )
	{
		m_rcValidImageArea = rc;
	}

	RECT CUIImageSource::GetNineGrid()
	{
		return m_rcNineGrid;
	}

	void CUIImageSource::SetNineGrid( RECT rc )
	{
		m_rcNineGrid = rc;
	}

	void CUIImageSource::ParseAttributes( LPCTSTR lpszAttr )
	{
		xml_document doc;
		if ( !doc.load(lpszAttr) )
			return;
		xml_node node = doc.first_child();
		xml_node::attribute_iterator it = node.attributes_begin();
		while ( it != node.attributes_end() )
		{
			xml_attribute attr = *it;
			CString szAttrName = attr.name();
			if ( szAttrName.CollateNoCase(_T("ResName")) == 0 )
			{
				m_szResName = attr.value();
			}
			else if ( szAttrName.CollateNoCase(_T("Source")) == 0 )
			{
				m_szImageFilePath = GetUICore()->GetSkinDir();
				m_szImageFilePath += attr.value();
			}
			else if ( szAttrName.CollateNoCase(_T("ValidArea")) == 0 )
			{
				CUIUtilityHelper::ParseRect(attr.value(), m_rcValidImageArea);
			}
			else if ( szAttrName.CollateNoCase(_T("NineGrid")) == 0 )
			{
				CUIUtilityHelper::ParseRect(attr.value(), m_rcNineGrid);
			}
			++it;
		}
	}

}